const fse = require('fs-extra');
const { readJSON, writeJSON } = require('json-reader-writer');

class JsonIO {
  constructor(filePath) {
    this.filePath = filePath;
  }

  read() {
    try {
      return readJSON(this.filePath);
    } catch (err) {
      return null;
    }
  }

  write(json) {
    fse.ensureFileSync(this.filePath);
    writeJSON(this.filePath, json);
  }
}

module.exports = JsonIO;
